//
//  MainViewController.m
//  10703
//
//  Created by student on 16/2/22.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "MainViewController.h"
#import "onViewController.h"
#import "TwoViewController.h"
#import "ThreeViewController.h"
int i=1;
int temp=1;
@interface MainViewController ()
@property (nonatomic,strong) onViewController *on;
@property (nonatomic,strong) TwoViewController *two;
@property (nonatomic,strong) ThreeViewController *three;
@end

@implementation MainViewController

- (onViewController *) one
{
    if (_on == nil)
    {
        _on = [[onViewController alloc] init];
    }
    return _on;
}
- (TwoViewController *) two
{
    if (_two == nil)
    {
        _two = [[TwoViewController alloc] init];
    }
    return _two;
}
- (ThreeViewController *) three
{
    if (_three == nil)
    {
        _three = [[ThreeViewController alloc] init];
    }
    return _three;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self FirstView:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)change
{
    [UIView beginAnimations:@"666" context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    if (temp > i)
    {
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
    }
    else if(temp < i)
    {
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
    }
    [UIView commitAnimations];//动画开始播放
}

- (IBAction)FirstView:(id)sender {
    i = 1;
    [self.view insertSubview:self.one.view atIndex:0];
    [self.two.view removeFromSuperview];
    [self.three.view removeFromSuperview];
    [self change];
    temp = i;
}
- (IBAction)SecondView:(id)sender {
    i = 2;
    [self.view insertSubview:self.two.view atIndex:0];
    [self.one.view removeFromSuperview];
    [self.three.view removeFromSuperview];
    [self change];
    temp = i;
}
- (IBAction)ThirdView:(id)sender {
    i = 3;
    [self.view insertSubview:self.three.view atIndex:0];
    [self.two.view removeFromSuperview];
    [self.one.view removeFromSuperview];
    [self change];
    temp = i;
}


@end
